﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace comix
{
    /// <summary>
    /// Summary description for createProfileAjax
    /// </summary>
    public class createProfileAjax : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            LCustomer c = (LCustomer)context.Session["customer"];
            string username = context.Request.Form["username"];
            string pwd = context.Request.Form["password"];
            string firstname = context.Request.Form["firstname"];
            string lastname = context.Request.Form["lastname"];
            string address = context.Request.Form["address"];
            string city = context.Request.Form["city"];
            string tk = context.Request.Form["tk"];
            string phone = context.Request.Form["phone"];
            int country = Convert.ToInt32(context.Request.Form["countryid"]);
            bool news = context.Request.Form["newsletter"] == "true";
            context.Response.ContentType = "text/plain";

            
            if (c.Register(username, pwd, "", firstname, lastname, false, news, address, city, tk, phone, country))
            {
                FormsAuthentication.SetAuthCookie("C" + c.Id.ToString(), false);
                context.Response.Write("OK");
            }
            else
            {
                context.Response.Write(c.LastError);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}